home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 004a / pbclon21.zip / MEMBOX.ASM < prev    next >
Assembly Source File  |  1992-12-07  |  10KB  |  223 lines

  1. ; MemBox 1.0  Copyright (c) 1992  Thomas G. Hanlin III
  2.  
  3. MEMSIZE   equ  4096    ; size of storage space, in bytes (must be below 32768)
  4.  
  5. RESLEN    equ  (Start - MemBox + 256 + 15) SHR 4
  6.  
  7.  
  8. Sseg          segment        byte stack 'prog'   ; dummy stack segment
  9. Sseg          ends
  10.  
  11.  
  12. Cseg          segment        byte public 'prog'
  13.               assume         cs:Cseg, ds:Cseg, es:Cseg, ss:Sseg
  14.  
  15.  
  16.               org            100h
  17.  
  18. MemBox        proc
  19.               jmp            Start          ;   skip code for resident routine
  20.               db MEMSIZE-3 dup(?)           ; storage area
  21. ; NOTE that the "JMP Start" code is construed as part of the storage area.
  22. MemBox        endp
  23.  
  24.  
  25.  
  26. INTRmux       proc                     ; multiplex interrupt ------------------
  27.               sti                           ; allow interrupts to occur
  28.               cmp            ah,0CFh        ; is it for us?
  29.               je             IM_OurMux      ;   yep, go process it
  30. IM_NormMux:   db 0EAh                       ; *** self-modifying code
  31.   MUXOFS      dw ?                          ; *** JMP FAR PTR xxxx:yyyy
  32.   MUXSEG      dw ?                          ; (original INT 2Fh vector)
  33.  
  34. IM_OurMux:    or             al,al          ; status request?
  35.               jnz            IM_OurMux1     ;   no, skip
  36.               dec            al             ; AL=0FFh to show we're here
  37.               iret                          ;   go directly home
  38. IM_OurMux1:   cmp            al,1           ; "remove self" request?
  39.               jne            IM_NormMux     ;   no, exit
  40.               mov            ax,0           ;
  41.               push           ax             ;
  42.               pop            es             ;
  43.               cli                           ; interrupts off
  44.               mov            ax,cs:MUXOFS   ;
  45.               mov            es:[00BCh],ax  ; restore old INT 2Fh vector
  46.               mov            ax,cs:MUXSEG   ;
  47.               mov            es:[00BEh],ax  ; restore old INT 2Fh vector
  48.               sti                           ; interrupts on
  49.               push           cs             ;
  50.               pop            es             ; return current segment in ES
  51.               iret                          ;   return to sender
  52. INTRmux       endp                     ; multiplex interrupt ------------------
  53.  
  54.  
  55.  
  56. Start         proc                     ; main program -------------------------
  57.               cld                           ; set direction forward
  58.               call           ParseCmdLine   ; parse the command line
  59.               jc             _Done          ;   if invalid, take error exit
  60.  
  61. _Start1:      cmp            TSR_OFF,0      ; remove TSR?
  62.               jz             _Start2        ;   no, skip it
  63.               mov            ax,0CF00h      ; check for TSR...
  64.               int            2Fh            ; ...on the multiplex interrupt
  65.               inc            al             ; is it installed?
  66.               jnz            _Start1A       ;   no, skip
  67.               mov            ax,0CF01h      ; tell it to remove itself
  68.               int            2Fh            ; (returns TSR segment in ES)
  69.               mov            ah,49h         ; free up TSRs memory
  70.               int            21h            ;
  71.               jmp            _Done          ;
  72. _NotInstMsg   db "MemBox is not resident",13,10,"$"
  73. _Start1A:     mov            ah,9           ; display a string
  74.               mov            dx,offset _NotInstMsg ; ptr to "Not installed"
  75.               int            21h            ;
  76.               mov            ERRCODE,1      ; set error code
  77.               jmp            _Done          ;
  78.  
  79. _Start2:      mov            ax,0CF00h      ; check for TSR...
  80.               int            2Fh            ; ...on the multiplex interrupt
  81.               inc            al             ; is it installed?
  82.               jz             _Start2A       ;   yep, skip out
  83.  
  84.               mov            es,ds:[002Ch]  ;
  85.               mov            bx,1           ; one paragraph
  86.               mov            ah,4Ah         ; shrink the environment
  87.               int            21h            ;
  88.  
  89.               cld                           ; set direction forward
  90.               mov            si,offset PROCNAME ; install name in mini-envirn
  91.               xor            di,di          ;
  92.               mov            cx,8           ; 16 bytes maximum
  93.               rep            movsw          ;
  94.  
  95.               mov            ds:[0080h],MEMSIZE ; store memory size for later
  96.  
  97.               mov            ax,352Fh       ; get multiplex int vect (INT 2Fh)
  98.               int            21h            ;
  99.               mov            MUXOFS,bx      ; save old misc system services
  100.               mov            MUXSEG,es      ;
  101.               mov            ax,252Fh       ; install new multiplex int vector
  102.               mov            dx,offset INTRmux ; ptr to our routine
  103.               int            21h            ;
  104.  
  105.               mov            dx,RESLEN      ; size of TSR in paragraphs
  106.               mov            ax,3100h       ; terminate and stay resident
  107.               int            21h            ;
  108.  
  109. _Done:        mov            ah,4Ch         ; terminate program w/ error code
  110.               mov            al,ERRCODE     ; get the error code
  111.               int            21h            ;
  112.  
  113. _Start2A:     mov            dx,offset _AlrInstMsg ; ptr to "Already installed"
  114. _Start2Z:     mov            ah,9           ; display a string
  115.               int            21h            ;
  116.               mov            ERRCODE,1      ; set error code
  117.               jmp            _Done          ;   go exit
  118.  
  119. _AlrInstMsg   db "MemBox is already resident",13,10,"$"
  120.  
  121. Start         endp                     ; main program -------------------------
  122.  
  123.  
  124.  
  125. ParseCmdLine  proc           near      ; parse the command line for parms -----
  126.               mov            si,0080h       ; ptr to length of command line
  127.               mov            ax,si          ; zero AH
  128.               lodsb                         ; length of command line
  129.               cmp            al,1           ; is it null or nearly so?
  130.               jbe            PCL_Help       ;   yep, go help 'em
  131.               mov            cx,ax          ; length of command line
  132.  
  133. PCL_ScanParms:
  134.               mov            di,si          ; update ptr to command line
  135.               mov            al,"/"         ; switch character
  136.               repne          scasb          ; see if we can find it
  137.               mov            si,di          ;
  138.               jne            PCL_Done       ;   no, go exit
  139.               jcxz           PCL_Done       ;   exit if no parms left
  140.               lodsb                         ; get option character
  141.               dec            cx             ; account for it
  142.               and            al,0DFh        ; convert it to uppercase
  143.               cmp            al,"D"         ; D>einstall?
  144.               je             PCL_Remove     ;   yep, take care of it
  145.               cmp            al,"I"         ; I>nstall?
  146.               jne            PCL_BadParm    ;   nope, error
  147.  
  148. PCL_Install:  mov            TSR_ON,1       ; set /Install flag
  149.               jmp            PCL_ScanParms  ;   go try for another parm
  150.  
  151. PCL_Remove:   mov            TSR_OFF,1      ; set /Deinstall flag
  152.               jmp            PCL_ScanParms  ;   go try for another parm
  153.  
  154. PCL_Done:     cmp            TSR_OFF,0      ; did we get an option?
  155.               jne            PCL_GoodExit   ;   yep, it's good
  156.               cmp            TSR_ON,0       ; did we get an option?
  157.               jne            PCL_GoodExit   ;   yep, it's good
  158.  
  159. PCL_Help:     mov            si,offset INFO ; ptr to info about MemBox
  160. PCL_ShowInfo: lodsb                         ; get a char
  161.               or             al,al          ; end of text?
  162.               jz             PCL_BadExit    ;   yep, go exit
  163.               cmp            al,0FFh        ; unprintable char?
  164.               jne            PCL_SI1        ;   no, go display it
  165.               mov            al," "         ; convert to space
  166. PCL_SI1:      mov            dl,al          ; get char ready to display
  167.               mov            ah,2           ; display a character
  168.               int            21h            ;
  169.               jmp            PCL_ShowInfo   ;   go for all chars
  170.  
  171. PCL_BadParm:  mov            ah,9           ; display a string
  172.               mov            dx,offset PCL_BadParmMsg ; ptr to "Invalid parm"
  173.               int            21h            ;
  174.               mov            ERRCODE,2      ; set error code
  175.               jmp            PCL_BadExit    ;   go exit
  176. PCL_BadParmMsg   db "Error: invalid parameter",13,10,"$"
  177.  
  178. PCL_BadExit:  stc                           ; set error flag
  179.               ret                           ;   return to sender
  180.  
  181. PCL_GoodExit: clc                           ; clear error flag
  182.               ret                           ;   return to sender
  183.  
  184. ParseCmdLine  endp                     ; parse the command line for parms -----
  185.  
  186.  
  187.  
  188. ; -------------------------- transient data area ------------------------------
  189.  
  190.  
  191.  
  192. INFO  db "MemBox 1.0  Copyright (c) 1992  Thomas G. Hanlin III",13,10
  193.       db 13,10
  194.       db "This TSR provides a fixed block of RAM for use as a data transfer area.",13,10
  195.       db 13,10
  196.       db "Syntax:",13,10
  197.       db "  MEMBOX       display info on MemBox",13,10
  198.       db "  MEMBOX /I    install MemBox",13,10
  199.       db "  MEMBOX /D    deinstall MemBox",13,10
  200.       db 0
  201.  
  202.  
  203.  
  204. ; These are flags set by ParseCmdLine according to the switches it finds.
  205.  
  206. TSR_OFF    db 0      ; whether to remove TSR from memory    /D
  207. TSR_ON     db 0      ; whether to install TSR               /I
  208.  
  209.  
  210.  
  211. ; The original environment will be discarded by the MemBox TSR, since it won't
  212. ; be needed and takes up space.  We'll install the following as the new name
  213. ; in a tiny environment, though, for the benefit of MAP utilities.
  214.  
  215. PROCNAME  db 0,0,1,0,"MEMBOX.COM",0,0
  216.  
  217.  
  218.  
  219. ERRCODE   db 0    ; number to return as ErrorLevel when program exits
  220.  
  221. Cseg          ends
  222.               end            MemBox
  223.